package com.youlv.yl.controller;


import com.youlv.yl.dto.CartDto;
import com.youlv.yl.dto.CartNumDto;
import com.youlv.yl.service.intf.CartService;
import com.youlv.yl.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fenghe
 * @since 2022-01-17
 */
@RestController
@RequestMapping("/yl/cart")
@Api(value = "实现购物车相关操作", tags = "实现购物车相关操作")
@CrossOrigin
public class CartController {
    @Autowired
    private CartService service;

    /** 添加购物车*/
    @PostMapping("add.do")
    public R add(@RequestBody CartDto dto) {
        return service.save(dto);
    }

    /** 修改数量*/
    @PostMapping("change.do")
    public R change(@RequestBody CartNumDto dto) {
        return service.change(dto);
    }

    /** 查询*/
    @GetMapping("all.do")
    public R all(String token) {
        return service.queryMy(token);
    }

    /** 删除*/
    @GetMapping("del.do")
    public R del(Long id) {
        return service.del(id);
    }

    @PostMapping("items.do")
    public R items(@RequestBody int[] ids){
        return service.queryIds(ids);
    }
}
